<!DOCTYPE html>
<html class="loginHtml">
<head>
	<meta charset="utf-8">
	<title>帮客卖家后台管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="icon" href="<?php echo ADMIN?>images/favicon.ico">
	<link rel="stylesheet" href="<?php echo _PUBLIC ?>layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="<?php echo ADMIN ?>css/public.css" media="all" />
</head>
<body class="loginBody">
	<form class="layui-form" id="form_login">
		<div class="login_face"><img src="<?php echo ADMIN ?>images/face.jpg" class="userAvatar"></div>
		<div class="layui-form-item input-item">
			<label for="userName">手机号</label>
			<input type="text" placeholder="请输入手机号" name="phone" autocomplete="off" id="userName" class="layui-input" lay-verify="required">
		</div>
		<div class="layui-form-item input-item">
			<label for="password">密码</label>
			<input type="password" placeholder="请输入密码" name="password" autocomplete="off" id="password" class="layui-input" lay-verify="required">
		</div>
		
		<div class="layui-form-item">
			<button class="layui-btn layui-block" id="login" lay-filter="login" lay-submit>登录</button>
		</div>
		<div class="layui-form-item">
			<a class="layui-btn layui-btn-primary layui-block" id="switch_reg">前往注册</a>
		</div>		
	</form>
	<form class="layui-form" id="form_reg" style="display:none">
		<div class="login_face"><img src="<?php echo ADMIN ?>images/face.jpg" class="userAvatar"></div>
		<div class="layui-form-item input-item">
			<label for="userName">手机号</label>
			<input type="text" placeholder="请输入手机号" name="phone" autocomplete="off" id="reg_phone" class="layui-input" lay-verify="required">
		</div>
		<div class="layui-form-item input-item">
			<label for="userName">请输入手机验证码</label>
			<input type="text" placeholder="请输入手机验证码" autocomplete="off" name="yzm" id="yzm" style="width:60%;display:inline" class="layui-input" lay-verify="required">
			<a id="send_sms" class="layui-btn layui-btn-primary" style="width:39%;float:right">发送验证码</a>
		</div>
		
		<div class="layui-form-item input-item">
			<label for="password">密码</label>
			<input type="password" placeholder="请输入密码" name="password" autocomplete="off" id="password" class="layui-input" lay-verify="required">
		</div>
		
		<div class="layui-form-item input-item">
			<label for="password">请再次输入密码</label>
			<input type="password" placeholder="请再次输入密码" autocomplete="off" name="password_reapeat" id="password_reapeat" class="layui-input" lay-verify="required">
		</div>
		
		<div class="layui-form-item">
			<button class="layui-btn layui-block" id="reg" lay-filter="reg" lay-submit>注册</button>
		</div>
		<div class="layui-form-item">
			<a class="layui-btn layui-btn-primary layui-block" id="switch_login">返回登录</a>
		</div>
			
	</form>
	<script type="text/javascript" src="<?php echo _PUBLIC ?>layui/layui.js"></script>
	<script type="text/javascript" src="<?php echo ADMIN ?>js/cache.js"></script>
</body>
<script type="text/javascript">
layui.use(['form','layer','jquery'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer
        $ = layui.jquery;

    $('#switch_login').click(function(){
    	$("#form_login").show();
    	$('#form_reg').hide();
    })
    
    $('#switch_reg').click(function(){
    	$("#form_reg").show();
    	$('#form_login').hide();
    })
    
    //表单输入效果
    $(".loginBody .input-item").click(function(e){
        e.stopPropagation();
        $(this).addClass("layui-input-focus").find(".layui-input").focus();
    })
    $(".loginBody .layui-form-item .layui-input").focus(function(){
        $(this).parent().addClass("layui-input-focus");
    })
    $(".loginBody .layui-form-item .layui-input").blur(function(){
        $(this).parent().removeClass("layui-input-focus");
        if($(this).val() != ''){
            $(this).parent().addClass("layui-input-active");
        }else{
            $(this).parent().removeClass("layui-input-active");
        }
    })
    
    $('#send_sms').click(function(){
    	var phone=$("#reg_phone").val();
    	console.log(phone);
    	if(!phone){
    		layer.msg('手机号不能为空');
    		return;
    	}
    	$.ajax({		//验证验证码
			type:'post',
			data:{phone:phone},
			dataType:'json',
			url:"<?php echo site_url('app/me/user/sendSms')?>",
			success:function(res){
				if(res.code==200){
					layer.msg('验证码发送成功');
				}else{
					layer.msg('验证码发送失败');
				}
				
			},
			fail:function(){
				layer.msg('验证码发送失败');
			}
		})
    })
    //注册
    form.on('submit(reg)', function(data){
    	var data=data.field;
    	if(!data.yzm){
    		layer.msg('验证码不能为空');
    	}else if(data.password!=data.password_reapeat){
    		layer.msg('两次密码输入不一致');
    	}else{
    		$.ajax({		//验证验证码
    			type:'post',
				data:{yzm:data.yzm},
				dataType:'json',
				url:"<?php echo site_url('app/me/user/checkSms')?>",
				success:function(res){
					if(res.code==200){
						$.ajax({
							type:'post',
							data:data,
							dataType:'json',
							url:"<?php echo site_url('seller/login/reg')?>",
							success:function(res){
								if(res.code==200){
									layer.msg('注册成功');
									location.href="<?php echo site_url('seller')?>";
								}else{
									layer.msg(res.msg);
								}
							},
							fail:function(){
								
							}
						})
					}else{
						layer.msg('手机验证码输入错误');
					}
					
				},
				fail:function(){
					
				}
    		})
    	}      
		return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    
    form.on('submit(login)', function(data){
    	
      $.ajax({
			type:'post',
			data:data.field,
			dataType:'json',
			url:"<?php echo site_url('seller/login/login')?>",
			success:function(res){
				if(res.code==200){
					layer.msg('登录成功');
					location.href="<?php echo site_url('seller')?>";
				}else{
					layer.msg(res.msg);
				}
			},
			fail:function(){
				
			}
		})
		return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    
})


</script>
</html>